//
//  TMBaseNavgationController.m
//  国学商家管理
//
//  Created by mac on 2018/6/19.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TMBaseNavgationController.h"
#import "UIImage+TMimageCloor.h"
@interface TMBaseNavgationController ()<UINavigationControllerDelegate>

@end

@implementation TMBaseNavgationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.barTintColor = [HXColor hx_colorWithHexRGBAString:@"#05B48D"];
    UINavigationBar * bar = self.navigationBar;
//imageWithColor:[HXColor hx_colorWithHexRGBAString:@"#009CFF"];
    UIImage *image = [[UIImage imageWithColor:[HXColor hx_colorWithHexRGBAString:@"#05B48D"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [bar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    [bar setShadowImage:[UIImage new]];
    self.navigationController.navigationBar.translucent = NO;
//    UIImage * back = [UIImage imageNamed:@"back"];
//    self.navigationBar.backIndicatorImage = back;
//    self.navigationBar.backIndicatorTransitionMaskImage = back;
    UIBarButtonItem *barButtonItemAppearance = [UIBarButtonItem appearance];
    // 将文字减小并设其颜色为透明以隐藏
    [barButtonItemAppearance setTitleTextAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:15], NSForegroundColorAttributeName: [UIColor whiteColor]} forState:UIControlStateNormal];
    
}

- (void)setTitle:(NSString *)title{
    [self.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor whiteColor]}];
}

- (UIViewController *)childViewControllerForStatusBarStyle{
    return self.topViewController;
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
    if (self.viewControllers.count > 0) { // 如果现在push的不是栈底控制器(最先push进来的那个控制器)
        viewController.hidesBottomBarWhenPushed = YES;
        // 设置导航栏返回按钮
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"返回白"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
        [self.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    }
    //真正的跳转
    [super pushViewController:viewController animated:animated];
}

- (void)back
{
    //这里用的是self, 因为self就是当前正在使用的导航控制器
    [self popViewControllerAnimated:YES];
}
@end
